﻿Public Class principal
    Private Sub principal_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        'dehabilita opciones que no son propias de un rol dado
        visibleMenuItems_ByRol(Usuario.Rol_Id)

    End Sub
    '
    ' EVENTOS DE APERTURA EN MODO SHOWDIALOG()
    '
    Private Sub AltaOrdenRMAToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AltaOrdenRMAToolStripMenuItem.Click
        altaOrdenRMA.MdiParent = Me
        altaOrdenRMA.Show()
    End Sub

    Private Sub ActualizarDatosToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ActualizarDatosToolStripMenuItem.Click
        actualizarCliente.MdiParent = Me
        actualizarCliente.Show()
    End Sub

    Private Sub GestiónToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GestiónToolStripMenuItem.Click
        altaCliente.MdiParent = Me
        altaCliente.Show()
    End Sub

    Private Sub AltaProductoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AltaProductoToolStripMenuItem.Click
        altaCatalogo.MdiParent = Me
        altaCatalogo.Show()
    End Sub

    Private Sub ActualizarInformaciónToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ActualizarInformaciónToolStripMenuItem.Click
        actualizarStock.MdiParent = Me
        actualizarStock.Show()
    End Sub

    Private Sub AsignaciónAVidrieraToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AsignaciónAVidrieraToolStripMenuItem.Click
        asigVidriera.MdiParent = Me
        asigVidriera.Show()
    End Sub

    Private Sub VentaInmediataToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VentaInmediataToolStripMenuItem.Click
        registrarVentaI.MdiParent = Me
        registrarVentaI.Show()
    End Sub

    Private Sub VentaPresupuestoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VentaPresupuestoToolStripMenuItem.Click
        registrarVentaP.MdiParent = Me
        registrarVentaP.Show()
    End Sub

    Private Sub GenerarPresupuestoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GenerarPresupuestoToolStripMenuItem.Click
        registrarPresupuesto.MdiParent = Me
        registrarPresupuesto.Show()
    End Sub

    Private Sub ListadoDeRMAToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListadoDeRMAToolStripMenuItem.Click
        consultaOrdenRMA.MdiParent = Me
        consultaOrdenRMA.Show()
    End Sub

    Private Sub GenerarToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GenerarToolStripMenuItem.Click
        generarSorteo.MdiParent = Me
        generarSorteo.Show()
    End Sub

    Private Sub ConsultaDeSorteoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ConsultaDeSorteoToolStripMenuItem.Click
        modificarSorteo.MdiParent = Me
        modificarSorteo.Show()
    End Sub

    Private Sub ImportarToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ImportarToolStripMenuItem1.Click
        Importar.MdiParent = Me
        Importar.Show()
    End Sub

    Private Sub ExportarToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExportarToolStripMenuItem1.Click
        Exportar.MdiParent = Me
        Exportar.Show()
    End Sub

    Private Sub VentasToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VentasToolStripMenuItem.Click
        informeCVentas.MdiParent = Me
        informeCVentas.MdiParent.StartPosition = FormStartPosition.CenterParent
        informeCVentas.Show()
    End Sub

    Private Sub ClientesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClientesToolStripMenuItem.Click
        informeCCliente.MdiParent = Me
        informeCCliente.Show()
    End Sub

    Private Sub CatálogoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CatálogoToolStripMenuItem.Click
        informeCCatalogo.MdiParent = Me
        informeCCatalogo.Show()
    End Sub

    Private Sub ConsultaDeOrdenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        ConsultarOrdenServicio.ShowDialog()
    End Sub

    Private Sub AltaServicioDomicilioToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AltaServicioDomicilioToolStripMenuItem.Click
        altaOrdenDeServicio.MdiParent = Me
        altaOrdenDeServicio.Show()
    End Sub

    Private Sub AltaOrdenDeLocalToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        altaOrdenDeServicio.MdiParent = Me
        altaOrdenDeServicio.Show()
    End Sub

    Private Sub ActualizarOrdenDeServicioToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ActualizarOrdenDeServicioToolStripMenuItem.Click
        frmAcualizarOrdenesServicioTecnico.MdiParent = Me
        frmAcualizarOrdenesServicioTecnico.Show()
    End Sub

    Private Sub ActualizarOrdenvendedorToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ActualizarOrdenvendedorToolStripMenuItem.Click
        ActualizarOrdenServicioVendedor.MdiParent = Me
        ActualizarOrdenServicioVendedor.Show()
    End Sub

    Private Sub AsignarTécnicoAOrdenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AsignarTécnicoAOrdenToolStripMenuItem.Click
        frmAsignarTecnico.MdiParent = Me
        frmAsignarTecnico.Show()
    End Sub

    Private Sub ServiciosTécnicosToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ServiciosTécnicosToolStripMenuItem.Click
        frmInformeCOrdenesServicios.MdiParent = Me
        frmInformeCOrdenesServicios.Show()
    End Sub

    Private Sub AcercaDeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AcercaDeToolStripMenuItem.Click

        acercaDe.ShowDialog()
    End Sub

    '-------------------------------------------
    'EVENTO PARA CERRAR O CAMBIAR DE USUARIO/ROL
    '-------------------------------------------
    Private Sub principal_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing

        Dim rst As DialogResult

        rst = MessageBox.Show("Si, para cerrar la aplicación" & vbNewLine _
                & "No, para hacer cambio de usuario" & vbNewLine _
                & "Cancelar, para seguir trabajando", "Confirme", _
                MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question)

        'casos posibles segun rsta messagebox
        If rst = Windows.Forms.DialogResult.Yes Then
            Global.System.Windows.Forms.Application.ExitThread()

        ElseIf rst = Windows.Forms.DialogResult.Cancel Then
            e.Cancel = True

        ElseIf rst = Windows.Forms.DialogResult.No Then
            Me.Dispose()
        End If
    End Sub

    '-------------------------------------------
    'FUNCIONES PARA CONTROL DE ITEMS POR ROL
    '-------------------------------------------
    'habilita o deshabilita todos los items
    Private Sub visibleMenuItems_All(ByVal visualize As Boolean)
        'RMA
        RMAToolStripMenuItem.Visible = visualize
        AltaOrdenRMAToolStripMenuItem.Visible = visualize
        ListadoDeRMAToolStripMenuItem.Visible = visualize

        'Sorteo
        SorteoToolStripMenuItem.Visible = visualize
        GenerarToolStripMenuItem.Visible = visualize
        ConsultaDeSorteoToolStripMenuItem.Visible = visualize

        'Servicio
        ServiciosToolStripMenuItem.Visible = visualize
        AltaServicioDomicilioToolStripMenuItem.Visible = visualize
        ActualizarOrdenDeServicioToolStripMenuItem.Visible = visualize
        ActualizarOrdenvendedorToolStripMenuItem.Visible = visualize
        AsignarTécnicoAOrdenToolStripMenuItem.Visible = visualize

        'Venta
        VentaToolStripMenuItem.Visible = visualize
        VentaInmediataToolStripMenuItem.Visible = visualize
        VentaPresupuestoToolStripMenuItem.Visible = visualize
        GenerarPresupuestoToolStripMenuItem.Visible = visualize

        'Cliente
        ClienteToolStripMenuItem.Visible = visualize
        GestiónToolStripMenuItem.Visible = visualize
        ActualizarDatosToolStripMenuItem.Visible = visualize

        'Informes
        InformesToolStripMenuItem.Visible = visualize
        ClientesToolStripMenuItem.Visible = visualize
        VentasToolStripMenuItem.Visible = visualize
        ServiciosTécnicosToolStripMenuItem.Visible = visualize
        CatálogoToolStripMenuItem.Visible = visualize
        ImportarToolStripMenuItem1.Visible = visualize
        ExportarToolStripMenuItem1.Visible = visualize

        'Catalogo
        CatalogoToolStripMenuItem.Visible = visualize
        AltaProductoToolStripMenuItem.Visible = visualize
        ActualizarInformaciónToolStripMenuItem.Visible = visualize
        AsignaciónAVidrieraToolStripMenuItem.Visible = visualize

    End Sub

    'habilita items segun el rol logeado
    Private Sub visibleMenuItems_ByRol(ByVal Rol_id As Integer)
        visibleMenuItems_All(False)


        'case 1: tecnico
        'case 2: vendedor
        'case 3: encargado
        'case 4: administrativo
        'case 5: administrador

        Select Case Rol_id
            Case 1
                'RMA
                RMAToolStripMenuItem.Visible = True
                'ordenes de servicio
                ServiciosToolStripMenuItem.Visible = True
                ActualizarOrdenDeServicioToolStripMenuItem.Visible = True
                'informes
                InformesToolStripMenuItem.Visible = True
                ServiciosTécnicosToolStripMenuItem.Visible = True
                ListadoDeRMAToolStripMenuItem.Visible = True

            Case 2
                'venta
                VentaToolStripMenuItem.Visible = True
                VentaInmediataToolStripMenuItem.Visible = True
                VentaPresupuestoToolStripMenuItem.Visible = True
                GenerarPresupuestoToolStripMenuItem.Visible = True
                'Cliente
                ClienteToolStripMenuItem.Visible = True
                GestiónToolStripMenuItem.Visible = True
                ActualizarDatosToolStripMenuItem.Visible = True
                'catalogo
                CatalogoToolStripMenuItem.Visible = True
                AltaProductoToolStripMenuItem.Visible = True
                ActualizarInformaciónToolStripMenuItem.Visible = True
                AsignaciónAVidrieraToolStripMenuItem.Visible = True
                'servicio
                ServiciosToolStripMenuItem.Visible = True
                AltaServicioDomicilioToolStripMenuItem.Visible = True
                ActualizarOrdenvendedorToolStripMenuItem.Visible = True
                'sorteo
                SorteoToolStripMenuItem.Visible = True
                ConsultaDeSorteoToolStripMenuItem.Visible = True
                'informe
                InformesToolStripMenuItem.Visible = True
                ClientesToolStripMenuItem.Visible = True
                VentasToolStripMenuItem.Visible = True
                ServiciosTécnicosToolStripMenuItem.Visible = True
                CatálogoToolStripMenuItem.Visible = True
                'RMA
                RMAToolStripMenuItem.Visible = True
                AltaOrdenRMAToolStripMenuItem.Visible = True
                ListadoDeRMAToolStripMenuItem.Visible = True

            Case 3
                'servicio
                ServiciosToolStripMenuItem.Visible = True
                AltaServicioDomicilioToolStripMenuItem.Visible = True
                AsignarTécnicoAOrdenToolStripMenuItem.Visible = True
                'sorteo
                SorteoToolStripMenuItem.Visible = True
                GenerarToolStripMenuItem.Visible = True
                'informe
                InformesToolStripMenuItem.Visible = True
                ClientesToolStripMenuItem.Visible = True
                VentasToolStripMenuItem.Visible = True
                ServiciosTécnicosToolStripMenuItem.Visible = True
                CatálogoToolStripMenuItem.Visible = True
                ExportarToolStripMenuItem1.Visible = True
            Case 4
                'informe
                InformesToolStripMenuItem.Visible = True
                ClientesToolStripMenuItem.Visible = True
                VentasToolStripMenuItem.Visible = True
                ServiciosTécnicosToolStripMenuItem.Visible = True
                CatálogoToolStripMenuItem.Visible = True
                ImportarToolStripMenuItem1.Visible = True
            Case 5
                'RMA
                RMAToolStripMenuItem.Visible = True
                AltaOrdenRMAToolStripMenuItem.Visible = True
                ListadoDeRMAToolStripMenuItem.Visible = True

                'Sorteo
                SorteoToolStripMenuItem.Visible = True
                GenerarToolStripMenuItem.Visible = True
                ConsultaDeSorteoToolStripMenuItem.Visible = True

                'Servicio
                ServiciosToolStripMenuItem.Visible = True
                AltaServicioDomicilioToolStripMenuItem.Visible = True
                ActualizarOrdenDeServicioToolStripMenuItem.Visible = True
                ActualizarOrdenvendedorToolStripMenuItem.Visible = True
                AsignarTécnicoAOrdenToolStripMenuItem.Visible = True

                'Venta
                VentaToolStripMenuItem.Visible = True
                VentaInmediataToolStripMenuItem.Visible = True
                VentaPresupuestoToolStripMenuItem.Visible = True
                GenerarPresupuestoToolStripMenuItem.Visible = True

                'Cliente
                ClienteToolStripMenuItem.Visible = True
                GestiónToolStripMenuItem.Visible = True
                ActualizarDatosToolStripMenuItem.Visible = True

                'Informes
                InformesToolStripMenuItem.Visible = True
                ClientesToolStripMenuItem.Visible = True
                VentasToolStripMenuItem.Visible = True
                ServiciosTécnicosToolStripMenuItem.Visible = True
                CatálogoToolStripMenuItem.Visible = True
                ImportarToolStripMenuItem1.Visible = True
                ExportarToolStripMenuItem1.Visible = True

                'Catalogo
                CatalogoToolStripMenuItem.Visible = True
                AltaProductoToolStripMenuItem.Visible = True
                ActualizarInformaciónToolStripMenuItem.Visible = True
                AsignaciónAVidrieraToolStripMenuItem.Visible = True
            Case Else
        End Select
    End Sub

    Private Sub MenuStrip1_ItemClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles MenuStrip1.ItemClicked

    End Sub
End Class